﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YLW.Common.Core.Model;
using YLW.Plat.Jhfw.HL7V3.XSDModels.MCCI_IN000002UV01;

namespace YLW.Plat.Jhfw.HL7V3.V3Message
{
    public class V3_MCCI_IN000002UV01
    {
        public static string MCCI_ResponseMessage(ApiBaseModel jsonData, string id_extension, string sender_name, string receiver_name)
        {
            string hl7Xml = string.Empty;

            if (jsonData == null)
            {
                return hl7Xml;
            }

            //根据XML XSD构建HL7 XML消息格式

            //创建根对象
            var xmlRoot = new MCCI_IN000002UV01
            {
                ITSVersion = "XML_1.0",
                id1 = new id1 { root = "2.16.156.10011.2.5.1.1", extension = Guid.NewGuid().ToString() },
                creationTime = new creationTime { value = DateTime.Now.ToString("yyyyMMddHHmmss") },
                interactionId = new interactionId { root = "2.16.156.10011.2.5.1.2", extension = "MCCI_IN000002UV01" },
                processingCode = new processingCode { code = "P" },
                processingModeCode = new processingModeCode(),
                acceptAckCode = new acceptAckCode { code = "AL" },
                receiver = new receiver
                {
                    typeCode = "RCV",
                    device1 = new device1
                    {
                        classCode = "DEV",
                        determinerCode = "INSTANCE",
                        id1 = new id1
                        {
                            item = new item
                            {
                                root = "2.16.156.10011.2.5.1.3",
                                extension = receiver_name
                            }
                        }
                    }
                },
                sender = new sender
                {
                    typeCode = "SND",
                    device1 = new device1
                    {
                        classCode = "DEV",
                        determinerCode = "INSTANCE",
                        id1 = new id1
                        {
                            item = new item
                            {
                                root = "2.16.156.10011.2.5.1.3",
                                extension = sender_name
                            }
                        }
                    }
                },
                acknowledgement = new acknowledgement
                {
                    typeCode = jsonData.subcode == "success" ? "AA" : "AE",
                    targetMessage = new id
                    {
                        id1 = new id1
                        {
                            root = "2.16.156.10011.2.5.1.1",
                            extension = id_extension
                        }
                    },
                    acknowledgementDetail = new acknowledgementDetail
                    {
                        text = new text
                        {
                            value = jsonData.submsg
                        }
                    }
                }
            };

            hl7Xml = HL7V3Helper.SerializeToXml(xmlRoot);

            return hl7Xml;
        }
    }
}
